{if !$_W['isajax']} {template 'common/header-gw'} {/if}
<script type="text/javascript">
require(['jquery', 'util'], function($, u) {
    $('#form1').submit(function(e) {
        // if ($.trim($(':text[name="username"]').val()) == '') {
        //     u.message('没有输入用户名.', '', 'error');
        //     return false;
        // }
        if ($('#password').val() == '') {
            u.message('没有输入密码.', '', 'error');
            return false;
        }
        if ($('#password').val().length < 8) {
            u.message('密码长度不能小于8个字符.', '', 'error');
            return false;
        }
        if ($('#password').val() != $('#repassword').val()) {
            u.message('两次输入的密码不一致.', '', 'error');
            return false;
        }
        if ($('#companyid option:selected').val() == 0) {
            u.message('请选择所属物业公司.', '', 'error');
            return false;
        }

    });
});
</script>
<div class="clearfix">
    <form action="{php echo $this->createWebUrl('users',array('op' => 'add'))}" method="post" class="form-horizontal" role="form" id="form1">
        <input type='hidden' name='uid' value="{$_GPC['uid']}" />
        <div class="form-group">
            <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">用户名</label>
            <div class="col-sm-10 col-lg-9 col-xs-12">
            {if $_GPC['uid']}
                <span class="uneditable-input form-control">{$user['username']}</span>
            {else}
                <input id="" name="username" type="text" class="form-control" value="{$user['username']}" />
                <span class="help-block">请输入用户名，用户名为 3 到 15 个字符组成，包括汉字，大小写字母（不区分大小写）</span>
            {/if}
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">密码</label>
            <div class="col-sm-10 col-lg-9 col-xs-12">
                <input id="password" name="password" type="password" class="form-control" value="" autocomplete="off" />
                <span class="help-block">请填写密码，最小长度为 8 个字符</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">确认密码</label>
            <div class="col-sm-10 col-lg-9 col-xs-12">
                <input id="repassword" type="password" class="form-control" value="" autocomplete="off" />
                <span class="help-block">重复输入密码，确认正确输入</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">所属物业</label>
            <div class="col-sm-10 col-lg-3 col-xs-3">
                <select name="companyid" class="form-control" id="companyid">
                    <option value="0">请选择所属物业</option>
                    {loop $list $row}
                    <option value="{$row['id']}" {if $user['companyid'] == $row['id']}selected = selected {/if}>{$row['title']}</option>
                    {/loop}
                </select>
            </div>
            <div class="col-sm-10 col-lg-3 col-xs-3">
                <select name="regionid" class="form-control" id="regionid">
                    <option value="0">请选择所属小区</option>
                    {loop $companies $row}
                    <option value="{$row['id']}" {if $user['regionid'] == $row['id']}selected = selected {/if}>{$row['title']}</option>
                    {/loop}
                </select>
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">备注</label>
            <div class="col-sm-10 col-lg-9 col-xs-12">
                <textarea id="" name="remark" style="height:80px;" class="form-control">{$user['remark']}</textarea>
                <span class="help-block">方便注明此用户的身份</span>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-md-offset-2 col-lg-offset-1 col-xs-12 col-sm-10 col-md-10 col-lg-11">
            <button type="submit" class="btn btn-primary span3" name="submit" value="提交">确认注册</button>
                <input type="hidden" name="token" value="{$_W['token']}" />
            </div>
        </div>
    </form>
</div>
<script type="text/javascript">
$(function() {
    $("#companyid").change(function() {
        var companyid = $("#companyid option:selected").val();
        if (companyid != '0') {
            $.getJSON("{php echo $this->createWebUrl('users',array('op' => 'ajax'))}", {companyid:companyid}, function (data) { 
                var content;
                for(var o in data){
                    content +="<option value="+data[o].id+" >"+data[o].title+"</option>";
                }
                $("#regionid").append(content);
            });
        } else {

        }
    });
})
</script>
{if !$_W['isajax']}
{template 'common/footer-gw'}
{/if}